//---------------------------------------------------------------------------

#ifndef InvoiceReport2H
#define InvoiceReport2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <QuickRpt.hpp>
#include <Qrctrls.hpp>
#include "InvoiceBridge.h"
#include "PaymentTypeBridge.h"
#include <QRCtrls.hpp>

class TInvoiceReport
{
   public:
      TInvoiceReport( TDatabase * database);
      ~TInvoiceReport();

      TQuery * GetQuery();
      TQuery * GetTotalAmountQuery();

      void Produce( int year, int month);
      void Close();

      bool isLastMonth;
      int  year;

   private:
      TQuery * qryInvoices;
      TQuery * qryTotalAmount;

      void BuildQuery();
};

//---------------------------------------------------------------------------

typedef struct _TBandDate
{
   bool show;
   TDateTime previous;
   TDateTime current;
} TBandDate;

typedef struct _TBandPage
{
   __int64 value;
   float amount;
} TBandPage;

class TTotalMonthlyPayment  : public TObject
{
   public:
      //AnsiString paymentType;
      __int64 paymentID;
      double amount;
};

class TTotalData
{
   public:
      double regularAmount;
      double cancelledAmount;
      TStringList* totalPayments;
      double yearAmount;

      TTotalData();
      virtual ~TTotalData();
      void Clear();
};


class TBandData
{
   public :
      TBandDate date;
      TBandPage page;
      TStringList * sorter;
      TStringList * cancelled;

      TBandData();
      ~TBandData();

      void Clear();
      void Add( TInvoice* invoice);
      bool IsCompleted( TInvoice* invoice);
};

//---------------------------------------------------------------------------
class TfrmInvoiceReport : public TForm
{
__published:	// IDE-managed Components
        TQuickRep *qrInvoices;
        TQRBand *bndTitle;
        TQRBand *bndHeader;
        TQRLabel *lblDate;
        TQRLabel *lblPage;
        TQRLabel *lblInvoice;
        TQRLabel *lblAmount;
        TQRLabel *lblCancelled;
        TQRBand *bndDetails;
        TQRBand *bndSummary;
        TQRLabel *lblTotalAmount;
        TQRLabel *lblTotalAmountValue;
        TQRLabel *lblTotalCancelledAmount;
        TQRLabel *lblTotalCancelledAmountValue;
        TQRLabel *lblTotalMonthlyAmount;
        TQRLabel *lblTotalMonthlyAmountValue;
        TQRLabel *lblDateValue;
        TQRLabel *lblPageValue;
        TQRLabel *lblInvoiceValue;
        TQRLabel *lblAmountValue;
        TQRLabel *lblCancelledValue;
        TQRLabel *lblTotalYearAmountValue;
        TQRLabel *lblYearAmount;
        TQRLabel *QRLabel4;
        TQRLabel *lblInvoiceReport;
        void __fastcall FormDestroy(TObject *Sender);
        void __fastcall bndSummaryBeforePrint(TQRCustomBand *Sender,
          bool &PrintBand);
        void __fastcall txtStatusPrint(TObject *sender, AnsiString &Value);
        void __fastcall qrInvoicesNeedData(TObject *Sender,
          bool &MoreData);
        void __fastcall qrInvoicesBeforePrint(TCustomQuickRep *Sender,
          bool &PrintReport);
private:
        TInvoiceReport * invoiceReport;
        TBandData      * bandData;
        TTotalData     * totalData;
        TDateTime        printedDate;
        int              printedPage;
        TPaymentTypeBridge* ptb;

        double getYearAmount();
        void PrintBandData();
        void PreparePaymentTypes();

public:
        __fastcall TfrmInvoiceReport(TComponent* Owner, TDatabase* dbMain);
        void Preview( int year, int month);
};
//---------------------------------------------------------------------------
#endif
